﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.sim {
    import Engine.Classes.*;
    import Engine.Helpers.*;
    import Classes.*;
    import Classes.util.*;
    import Modules.bandits.*;
    import Classes.actions.*;
    import Engine.*;

    public class CopHelicopterActionSelection implements IActionSelection {

        protected const FUCKING_XOFFSET:Number = -5;
        protected const FUCKING_YOFFSET:Number = -5;
        protected const FUCKING_ZOFFSET:Number = 2.5;

        private var m_copter:Helicopter;
        private var m_scenes:Array;
        private var m_soundLoop:SoundObject;
        private var m_helipad:MapResource;

        public function CopHelicopterActionSelection(_arg1:Helicopter){
            this.m_scenes = [];
            super();
            this.m_copter = _arg1;
            if (this.soundLoop){
                this.soundLoop.pause();
            };
        }
        public function addTargetScene(_arg1:Vector3):void{
            if (_arg1){
                this.m_scenes.push(_arg1);
                if ((((this.m_scenes.length == 1)) && (!((this.m_copter.getStateMachine().getState() is ActionElevate))))){
                    this.m_copter.clearStates();
                };
            };
        }
        public function getNextActions():Array{
            var _local2:Vector3;
            var _local1:SelectionResult = SelectionResult.FAIL;
            _local1 = this.goToTarget();
            if (_local1 == SelectionResult.FAIL){
                _local1 = this.goToHelipad();
            } else {
                this.m_helipad = null;
            };
            if (_local1 == SelectionResult.FAIL){
                _local1 = this.goToSunset();
            };
            if (_local1.actions.length == 0){
                _local2 = this.convertHotspotToNavigation(this.m_helipad.getHotspots("helipad")[0]);
                this.m_copter.setPosition(_local2.x, _local2.y, _local2.z);
                this.m_copter.conditionallyReattach(true);
            };
            return (_local1.actions);
        }
        protected function get soundLoop():SoundObject{
            if (!this.m_soundLoop){
                this.m_soundLoop = Sounds.play("helicopter", 0, Sounds.LOOPING);
            };
            return (this.m_soundLoop);
        }
        protected function goToTarget():SelectionResult{
            var insert:* = null;
            if ((((this.m_scenes.length == 0)) || (!(this.m_copter)))){
                return (SelectionResult.FAIL);
            };
            var pos:* = this.m_scenes[0];
            if (this.m_helipad){
                insert = new ActionElevate(this.m_copter, (BanditManager.COPTER_FLY_HEIGHT * 0.8));
            } else {
                insert = new ActionFn(this.m_copter, function ():void{
                });
            };
            return (new SelectionResult(this.m_copter, [new ActionFn(this.m_copter, function ():void{
                m_copter.showShadow = true;
                m_copter.animation = "static";
                if (((soundLoop) && (!(m_soundLoop.isPlaying())))){
                    m_soundLoop.unpause();
                };
            }), insert, new ActionFn(this.m_copter, function ():void{
                m_copter.depthSwapObject = null;
            }), new ActionNavigateBeeline(this.m_copter, pos.add(new Vector3(0, 0, (BanditManager.COPTER_FLY_HEIGHT * 0.8)))), new ActionElevate(this.m_copter, 0).setVelocityScale(0.6).setEase(ActionNavigateBeeline.EASE_QUAD_OUT), new ActionPause(this.m_copter, 2), new ActionElevate(this.m_copter, (BanditManager.COPTER_FLY_HEIGHT * 0.4)).setDirection(Item.DIRECTION_S).setVelocityScale(0.6).setEase(ActionNavigateBeeline.EASE_QUAD_IN), new ActionFn(this.m_copter, function ():void{
                m_scenes.shift();
            })]));
        }
        protected function goToHelipad():SelectionResult{
            if (((this.m_helipad) && (Global.world.getObjectById(this.m_helipad.getId())))){
                return (new SelectionResult(this.m_copter, []));
            };
            this.m_helipad = this.findClosestHelipad();
            if (((!(this.m_helipad)) || (!(BanditManager.isActiveCopter(this.m_copter))))){
                return (SelectionResult.FAIL);
            };
            var pos:* = this.convertHotspotToNavigation(this.m_helipad.getHotspots("helipad")[0]);
            return (new SelectionResult(this.m_copter, [new ActionFn(this.m_copter, function ():void{
                m_copter.animation = "static";
                if (((soundLoop) && (!(m_soundLoop.isPlaying())))){
                    m_soundLoop.unpause();
                };
            }), new ActionNavigateBeeline(this.m_copter, pos.add(new Vector3(0, 0, (BanditManager.COPTER_FLY_HEIGHT * 0.8)))), new ActionFn(this.m_copter, function ():void{
                m_copter.showShadow = false;
                m_copter.depthSwapObject = m_helipad;
            }), new ActionElevate(this.m_copter, pos.z).setDirection(Item.DIRECTION_SW).setVelocityScale(0.6).setEase(ActionNavigateBeeline.EASE_QUAD_OUT), new ActionFn(this.m_copter, function ():void{
                m_copter.animation = "idle";
                if (soundLoop){
                    Sounds.stop(m_soundLoop);
                    m_soundLoop = null;
                };
            })]));
        }
        protected function goToSunset():SelectionResult{
            var view_y:* = Global.stage.y;
            var view_height:* = (Global.stage.stageHeight / 2);
            var view_x:* = Global.stage.x;
            var view_width:* = Global.stage.stageWidth;
            var startX:* = ((view_width + view_x) + 20);
            var startY:* = (view_y + view_height);
            var endPos:* = IsoMath.screenPosToTilePos((startX + 200), (startY + MathUtil.randomIncl(200, -200)));
            return (new SelectionResult(this.m_copter, [new ActionFn(this.m_copter, function ():void{
                m_copter.animation = "static";
                if (((soundLoop) && (!(m_soundLoop.isPlaying())))){
                    m_soundLoop.unpause();
                };
            }), new ActionNavigateBeeline(this.m_copter, new Vector3(endPos.x, endPos.y, BanditManager.COPTER_FLY_HEIGHT)), new ActionFn(this.m_copter, function ():void{
                Sounds.stop(m_soundLoop);
                BanditManager.cleanUpHelicopter(m_copter);
            }), new ActionDie(this.m_copter)]));
        }
        protected function findClosestHelipad():MapResource{
            var _local4:MapResource;
            var _local5:Number;
            var _local6:Number;
            var _local7:Number;
            if (!this.m_copter){
                return (null);
            };
            var _local1:Array = Global.world.getObjectsByPredicate(BanditUtil.isPolice);
            var _local2:MapResource;
            var _local3:Number = -1;
            for each (_local4 in _local1) {
                if (Global.gameSettings.getPoliceStationLevel(_local4.getItem().name) < 6){
                } else {
                    _local5 = (_local4.getPosition().x - this.m_copter.getPosition().x);
                    _local6 = (_local4.getPosition().y - this.m_copter.getPosition().y);
                    _local7 = ((_local5 * _local5) + (_local6 * _local6));
                    if (((!(_local2)) || ((_local7 < _local3)))){
                        _local2 = _local4;
                        _local3 = _local7;
                    };
                };
            };
            return (_local2);
        }
        protected function convertHotspotToNavigation(_arg1:Vector3):Vector3{
            var _local2:Vector3 = _arg1.clone();
            _local2.x = (_local2.x + this.FUCKING_XOFFSET);
            _local2.y = (_local2.y + this.FUCKING_YOFFSET);
            _local2.z = this.FUCKING_ZOFFSET;
            return (_local2);
        }

    }
}//package Classes.sim 
